package com.rs.game.player.content.dungeoneering;

import com.rs.game.Animation;
import com.rs.game.player.Player;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;



public class Skilling {

	public static int SMITHING = 28;

	public static int[] ORES = { 17630, 17636, 17638, 17640, 17642, 17644, 17646 };
	public static int[] BARS = { 17650, 17656, 17658, 17660, 17662, 17664, 17666 };

	public static void sendRuneCraftingInterface(Player player) {
		player.getInterfaceManager().sendInterface(619);
	}

	public static void craftRune(int rune) {
	}

	public static void sendFurnaceInterface(Player player) {
		for (int i = 0; i < 45; i++) {
			player.getPackets().sendIComponentText(SMITHING, i, " ");
		}
		player.getPackets().sendIComponentText(SMITHING, 3, "ALL the ores in your inventory will be turned into bars.");
		player.getPackets().sendIComponentText(SMITHING, 19, "Select a bar to create.");
		player.getPackets().sendIComponentText(SMITHING, 42, "Novite");
		player.getPackets().sendIComponentText(SMITHING, 39, "Kratonium");
		player.getPackets().sendIComponentText(SMITHING, 37, "Fractite");
		player.getPackets().sendIComponentText(SMITHING, 34, "Zephyrium");
		player.getPackets().sendIComponentText(SMITHING, 31, "Argonite");
		player.getPackets().sendIComponentText(SMITHING, 28, "Katagon");
		player.getPackets().sendIComponentText(SMITHING, 25, "Gorgonite");
		player.getPackets().sendIComponentText(SMITHING, 22, "Promethium");
		player.getInterfaceManager().sendInterface(SMITHING);
	}

	public static void handleSmithingButtons(Player player, int buttonId, int slotId) {
		if (buttonId == 43) {
			player.getPackets().sendGameMessage("Novite.");
			setSmithing(player, ORES[0], 0);
		}
		if (buttonId == 40) {
			player.getPackets().sendGameMessage("Kratonium.");
			setSmithing(player, ORES[1], 1);
		}
		if (buttonId == 36) {
			player.getPackets().sendGameMessage("Fractite.");
			setSmithing(player, ORES[2], 2);
		}
		if (buttonId == 33) {
			player.getPackets().sendGameMessage("Zephyrium.");
			setSmithing(player, ORES[3], 3);
		}
		if (buttonId == 30) {
			player.getPackets().sendGameMessage("Argonite.");
			setSmithing(player, ORES[4], 4);
		}
		if (buttonId == 27) {
			player.getPackets().sendGameMessage("Katagon.");
			setSmithing(player, ORES[5], 5);
		}
		if (buttonId == 24) {
			player.getPackets().sendGameMessage("Gorgonite.");
			setSmithing(player, ORES[6], 6);
		}
		if (buttonId == 21) {
			player.getPackets().sendGameMessage("Promethium.");
			setSmithing(player, ORES[7], 7);
		}
	}

	public static void setSmithing(Player player, int ore, int i) {
		if (player.getInventory().containsItem(ore, 1)) {
			int amount = player.getInventory().getNumerOf(ore);
			beginSmithing(player, ore, amount, i);
		} else {
			player.getPackets().sendGameMessage("<col=ff0000>You don't have any ore of that kind.");
		}
	}

	public static void beginSmithing(final Player player, final int ore, final int amount, final int j) {
		player.addBoneDelay(5);
		player.closeInterfaces();
		player.getInventory().deleteItem(ore, 1);
		player.setNextAnimation(new Animation(899));
		player.getPackets().sendGameMessage("You place the bar into the furnace... ");
		WorldTasksManager.schedule(new WorldTask() {			
			@Override
			public void run() {
				player.getInventory().addItem(BARS[j], 1);
				player.getPackets().sendGameMessage("...you smelt the ore into a bar.");
				if (player.getInventory().containsItem(ore, 1) && player.getInventory().hasFreeSlots()) {
					beginSmithing(player, ore, amount, j);
				} else if (player.getInventory().containsItem(ore, 1) && !player.getInventory().hasFreeSlots()) {
					player.getPackets().sendGameMessage("You've ran out of inventory space.");
				} else if (player.getInventory().containsItem(ore, 1) && !player.getInventory().hasFreeSlots()) {
					player.getPackets().sendGameMessage("You've ran out of ores.");
				}
			}
		});
	}

}
